package com.ruoyi.coupons.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;

import com.ruoyi.coupons.mapper.TCouponMapper;
import com.ruoyi.coupons.vo.MemberEcharts;
import com.ruoyi.coupons.vo.gender;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;


@RestController
@RequestMapping("/system/bing")
public class EchartsController extends BaseController {
    @Autowired
    private TCouponMapper memberMapper;
    /**
     * 查询年龄分段
     * @return
     */
    //饼状图
    @GetMapping("/pie")
    public AjaxResult pie(){
        List<MemberEcharts> member = memberMapper.selectAge();
        ArrayList<MemberEcharts> memberEcharts = new ArrayList<>();
        for (MemberEcharts echarts : member) {
            MemberEcharts memberEcharts1 = new MemberEcharts();
            memberEcharts1.setName(echarts.getName());
            memberEcharts1.setValue(echarts.getValue());
            memberEcharts.add(memberEcharts1);
        }
        //打印台数据
        for (MemberEcharts memberEchart : memberEcharts) {
            System.out.println("饼状图数据"+"=========="+memberEchart.getName()+memberEchart.getValue());
        }

        return AjaxResult.success(memberEcharts);
    }
    /**
     * 查询年龄分段
     * @return
     */
    @GetMapping(value = "/zhu")
    public AjaxResult zhu(){
        List<gender> genders = memberMapper.selectGender();
        ArrayList<gender> genderArrayList = new ArrayList<>();
        for (gender gender1 : genders) {
            gender gender = new gender();
            gender.setGender(gender1.getGender());
            gender.setCount(gender1.getCount());
            genderArrayList.add(gender);
        }
        //打印台数据
        for (gender gender : genderArrayList) {
            System.out.println("柱状图数据"+"=========="+gender.getGender()+gender.getCount());
        }
        return AjaxResult.success(genderArrayList);
    }
}

